package com.letfox.test.example;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.letfox.common.util.UUIDHexGenerator;
import com.letfox.finance.dao.AccountDao;
import com.letfox.finance.enums.FINDelEnums;
import com.letfox.finance.model.FINAccount;
import com.letfox.test.util.MyBatisUtil;

public class FINAccountExample {

	private AccountDao accountcDao;
	
	@Test
	public void addAccount(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		FINAccount finAccount = new FINAccount();
		finAccount.setFinAccountId(UUIDHexGenerator.generator());
		finAccount.setFinAccount(UUIDHexGenerator.generator());
		finAccount.setFinAvailAmount(new BigDecimal("100"));
		finAccount.setFinTotalIncome(new BigDecimal("150"));
		finAccount.setFinTotalOutcome(new BigDecimal("50"));
		finAccount.setCreateTime(new Date());
		finAccount.setUpdateTime(new Date());
		finAccount.setCreateBy("admin");
		finAccount.setUpdateBy("admin");
		finAccount.setDel(FINDelEnums.UDMDel.EFFECTIVE.getValue());
		accountcDao = session.getMapper(AccountDao.class);
		accountcDao.insertSelective(finAccount);
	}
	
	@Test
	public void updateAccount(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		FINAccount finAccount = new FINAccount();
		finAccount.setDel(FINDelEnums.UDMDel.DELETE.getValue());
		accountcDao = session.getMapper(AccountDao.class);
		accountcDao.updateByPrimaryKeySelective(finAccount);
	}
	
	@Test
	public void selectAccount(){
		SqlSession session = MyBatisUtil.getSqlSession(true);
		
		String accoutId = "40289a81628943470162894347380000";
		accountcDao = session.getMapper(AccountDao.class);
		FINAccount finAccount = accountcDao.selectByPrimaryKey(accoutId);
		System.out.println(finAccount.toString());
	}

}
